在树莓派上配置 Clash 代理

编译 clash 源码

1git clone https://github.com/Dreamacro/clash.git
2cd clash
3go build
4sudo cp clash /usr/bin

如果遇到依赖包无法下载的问题,可以配置 GOPROXY,参考 goproxy.io

1$ export GOPROXY=https://proxy.golang.com.cn,direct

如果遇到 package embed is not in GOROOT 的问题, 这是因为 debian bullseye 的 golang 版本为 1.15,而 embed 是 1.16 版本新增的。

可以安装 bullseye-backports 的版本。

1$ apt policy golang-go
2golang-go:
3  Installed: 2:1.15~1
4  Candidate: 2:1.15~1
5  Version table:
6     2:1.19~1~bpo11+1 100
7        100 https://mirrors.tuna.tsinghua.edu.cn/debian bullseye-backports/main arm64 Packages
8        100 /var/lib/dpkg/status
9 *** 2:1.15~1 500
10        500 https://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main arm64 Packages
11
12$ sudo apt install golang-go=2:1.19~1~bpo11+1 golang-src=2:1.19~1~bpo11+1

编辑配置文件

配置文件的文件名默认为 config.yaml,可以放在任何路径。本文放在 /etc/clash 目录中。

启动 clash

1$ clash -d /etc/clash

如果遇到 Can't find MMDB, start download 并且下载失败的问题,可以手动下载并放到配置文件目录中。

1$ wget https://cdn.jsdelivr.net/gh/Dreamacro/maxmind-geoip@release/Country.mmdb -P /etc/clash/

配置 systemd service

创建 /usr/lib/systemd/system/clash.service 文件:

如果要配置为用户级服务,则文件路径为 /usr/lib/systemd/user/clash.service

后续命令需要附加 --user 选项,且不使用 sudo

1[Unit]
2Description=Clash proxy
3After=syslog.target systemd-user-sessions.service
4
5[Service]
6Type=simple
7ExecStart=/usr/bin/clash -d /etc/clash
8ExecStop=pkill clash
9Restart=on-failure
10RestartSec=2
11
12[Install]
13WantedBy=multi-user.target

更新配置

1$ sudo systemctl daemon-reload

启动 clash

1$ sudo systemctl start clash.service

查看启动是否成功

1$ sudo systemctl status clash.service

设置自动启动

1$ sudo systemctl enable clash.service

配置代理

gsettings

1$ gsettings set org.gnome.system.proxy mode manual
2$ gsettings set org.gnome.system.proxy.http host localhost
3$ gsettings set org.gnome.system.proxy.http port 7890
4$ gsettings set org.gnome.system.proxy.http enabled true
5$ gsettings set org.gnome.system.proxy use-same-proxy true

环境变量

1echo 'export all_proxy=localhost:7890' >> ~/.bashrc